package qeug.shsh.facde.controller;

import com.alibaba.nacos.common.utils.StringUtils;
import com.bes.enterprise.logging.internal.Log;
import com.bes.enterprise.logging.internal.LogFactory;
import com.drew.lang.annotations.NotNull;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.openapi.common.custom.annotation.ApiController;
import kd.bos.openapi.common.custom.annotation.ApiPostMapping;
import kd.bos.openapi.common.custom.annotation.ApiRequestBody;
import kd.bos.openapi.common.result.CustomApiResult;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import qeug.shsh.facde.info.SupplierInfo;
import qeug.shsh.facde.resultext.SupplierResulText;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


/**
 * 荒废，荒废，荒废，荒废，荒废，荒废，荒废，荒废，荒废，荒废，荒废，荒废
 **/
@ApiController(value = "SaveSupplierController",desc = "供应商保存api接口，自定义插件")
public class SaveSupplierController implements Serializable {
    /*private final static Log logger = LogFactory.getLog(SaveSupplierController.class);

    @ApiPostMapping(value = "/shsh_supplierSave", desc = "供应商保存api接口")
    public CustomApiResult<SupplierResulText> SHSupplierSave
            (@NotNull @Valid @ApiRequestBody(value = "入参") SupplierInfo supplierInfo) {
        *//**
         * 返回值对象
         *//*
        SupplierResulText supplierResulText = new SupplierResulText();
        int failCount = 0;//失败数量
        int successCount = 0;//成功数量
        *//**
         * 返回信息
         *//*
        SupplierResulText.ResultBean resultBean = new SupplierResulText.ResultBean();
        ArrayList<SupplierResulText.ResultBean> results = new ArrayList<>();
        *//**
         * 接口日志
         *//*
        StringBuilder msgBuilder = new StringBuilder();
        // 供应商入参集合
        List<SupplierInfo.DataBean> data = supplierInfo.getData();
        for (int i = 0; i < data.size(); i++) {
            SupplierInfo.DataBean dataBean = data.get(i);
            String number = dataBean.getMDM_NO();
            if (StringUtils.isBlank(number)) {
                msgBuilder.append("第").append(i).append("条数据，编码为空不能保存!");
                SupplierResulText.ResultBean failure = SupplierResulText.failure(i, "客户编码不能为空", number, "bar_save");
                results.add(failure);//将返回结果数据存放到集合中
                supplierResulText.setResult(results);//将集合重新传给返回值参数
                failCount++;//错误信息+1
            }
            QFilter filter = new QFilter("number", "=", number);
            DynamicObject bill = BusinessDataServiceHelper.loadSingle("bd_supplier", "id", new QFilter[]{filter});
            //判断是否存在该供应商(准备同步数据到这边)
            if (bill != null) {//如果存在,修改
                bill = BusinessDataServiceHelper.loadSingle(bill.get("id").toString(), "bd_supplier");
            } else {//不存在,新增
                //创建单据对象
                bill = BusinessDataServiceHelper.newDynamicObject("bd_supplier");
            }
            bill.set("number", number);//供应商编码

            //获取供应商名称----------必填
            String name = dataBean.getNAME1();
            if (StringUtils.isBlank(name)) {
                msgBuilder.append("第").append(i).append("条数据，编码为空不能保存。");
                SupplierResulText.ResultBean failure = SupplierResulText.failure(i, "供应商名称不能为空", name, "bar_save");
                results.add(failure);//将返回结果数据存放到集合中
                supplierResulText.setResult(results);//将集合重新传给返回值参数
                failCount++;//错误信息+1
//                continue;//重新进入方法
            }
            bill.set("name", name);

            //创建组织-------------必填
            String createorgName = dataBean.getCREATEORG();
            DynamicObject createorg = null;
            if (StringUtils.isBlank(createorgName)) {
                msgBuilder.append("第").append(i).append("条数据，物料编码：").append(name).append("，创建组织为空不能保存。");
                SupplierResulText.ResultBean failure = SupplierResulText.failure(i, "创建组织不能为空", name, "bar_save");
                results.add(failure);//将返回结果数据存放到集合中
                supplierResulText.setResult(results);//将集合重新传给返回值参数
                failCount++;//错误信息+1
            } else {
                QFilter f1 = new QFilter("name", "=", name);
                createorg = BusinessDataServiceHelper.loadSingle("bd_supplier", "id", new QFilter[]{f1});
                if (createorg == null) {
                    msgBuilder.append("第").append(i).append("条数据，物料编码：").append(number)
                            .append("，根据创建组织createorgName：").append(createorgName).append("没有查询到对应的信息不能保存。");
                    SupplierResulText.ResultBean failure = SupplierResulText.failure(i, "根据入参createorgName:" + createorgName + ",没有查询到对应信息", createorgName, "bar_save");
                    results.add(failure);//将返回结果数据存放到集合中
                    supplierResulText.setResult(results);//将集合重新传给返回值参数
                    failCount++;//错误信息+1
                }
                bill.set("createorg", createorg);//创建组织
            }

        }
        supplierResulText.setFailCount(failCount);
        return CustomApiResult.success(supplierResulText);
    }*/
}
